package leetcode.editor.cn;

/**
 * 冒泡排序
 */
public class ABubbleSort implements AIOrder{
    @Override
    public void sort(int[] nums) {
        for (int i = nums.length -1; i >= 1; i--) {
            boolean isChange = false;
            for (int j = 0; j < i; j++) {
                if (nums[j] > nums[j+1]) {
                    isChange = true;
                    nums[j] ^= nums[j+1];
                    nums[j+1] ^= nums[j];
                    nums[j] ^= nums[j+1];
                }
            }
            if (!isChange) {
                break;
            }
        }
    }

    public static void main(String[] args) {
        AIOrder order = new ABubbleSort();
        int[] nums = new int[]{8, 9, 1, 7, 2, 3, 5, 4, 6, 0};
        order.sort(nums);
        System.out.println("end");
    }
}
